package com.demos.springcloud.gateway06_custGlobalFilter.filters;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * 自定义全局过滤器
 */
@Component
public class GlobalFilter01 implements GlobalFilter, Ordered {

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        System.out.println(Thread.currentThread().getName() + " global_pre：" + System.currentTimeMillis()); //前置方法
        return chain.filter(exchange)
                .then(Mono.fromRunnable(() -> System.out.println(Thread.currentThread().getName() + " global_aft：" + System.currentTimeMillis())));
    }

    @Override
    public int getOrder() {
        return 5;
    }
}
